﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Dokan;

namespace MirrorDrive
{
    public class ExceptionHelper
    {
        public static int GetReturnCode(Exception ex)
        {
            int ret = 0;
            if (ex.GetType() == typeof(DirectoryNotFoundException))
            {
                ret = DokanNet.ERROR_PATH_NOT_FOUND;
            }
            else if (ex.GetType() == typeof(FileNotFoundException))
            {
                ret = DokanNet.ERROR_FILE_NOT_FOUND;
            }
            else if (ex.GetType() == typeof(UnauthorizedAccessException))
            {
                ret = DokanNet.ERROR_ACCESS_DENIED;
            }
            else if (ex.GetType() == typeof(IOException))
            {
                ret = Marshal.GetHRForException(ex);
            }
            else
            {
                ret = DokanNet.DOKAN_ERROR;
            }

            if (ret > 0)
                ret = -ret;

            return ret;
        }       
    }
}
